//Jonathan Flessner
//27-April-2014
//test scoreFor function
//int scoreFor (int player, struct gameState *state)
//for dominion.class
//modeled off of testUpdateCoins.c

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

#define TEST_SIZE 10

int main() {
    int i, p, handCount = 0, discardCount = 0, deckCount = 0;
    int numPlayers = 1;
    int seed = 50;
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
    struct gameState gS;
    int curseVal = -1, estateVal = 1, duchyVal = 3, provinceVal = 6, great_hallVal = 1;
    
    // arrays of all curses
    int curseA[TEST_SIZE];
    int estateA[TEST_SIZE];
    int duchyA[TEST_SIZE];
    int provinceA[TEST_SIZE];
    int great_hallA[TEST_SIZE];
    int gardensA[TEST_SIZE];
    for (i = 0; i < TEST_SIZE; i++)
    {
        curseA[i] = curse;
        estateA[i] = estate;
        duchyA[i] = duchy;
        provinceA[i] = province;
        great_hallA[i] = great_hall;
        gardensA[i] = gardens;
    }

    for(p = 0; p < numPlayers; p++)
    {
        for(handCount = 0; handCount <= TEST_SIZE; handCount++)
        {		
            memset(&gS, 23, sizeof(struct gameState));                                          // clear game state
            initializeGame(2, k, seed, &gS);                                                    // initialize
            gS.handCount[p] = handCount;                                                        // set handCount
            memcpy(gS.hand[p], curseA, sizeof(int) * handCount);                                // set all the cards to curses
            if(!(scoreFor(p,&gS) == handCount * curseVal)){                                     // assert correctness
                printf("FAIL - Test player %d with %d curse cards in hand.\n", p, handCount);
                printf("Score = %d, expected = %d\n", scoreFor(p,&gS), handCount * curseVal);
            } 							

            memset(&gS, 23, sizeof(struct gameState));   								
            initializeGame(2, k, seed, &gS); 											
            gS.handCount[p] = handCount;                 								
            memcpy(gS.hand[p], estateA, sizeof(int) * handCount); 						
            if(!(scoreFor(p,&gS) == handCount * estateVal)){
                printf("FAIL - Test player %d with %d estate cards in hand.\n", p, handCount);
                printf("Score = %d, expected = %d\n", scoreFor(p,&gS), handCount * estateVal);
            }      
            
            memset(&gS, 23, sizeof(struct gameState));   
            initializeGame(2, k, seed, &gS); 
            gS.handCount[p] = handCount;                 
            memcpy(gS.hand[p], duchyA, sizeof(int) * handCount); 
            if(!(scoreFor(p,&gS) == handCount * duchyVal)){
                printf("FAIL - Test player %d with %d duchy cards in hand.\n", p, handCount);
                printf("Score = %d, expected = %d\n", scoreFor(p,&gS), handCount * duchyVal);
            }      
           
            memset(&gS, 23, sizeof(struct gameState));   
            initializeGame(2, k, seed, &gS); 
            gS.handCount[p] = handCount;                 
            memcpy(gS.hand[p], provinceA, sizeof(int) * handCount); 
            if(!(scoreFor(p,&gS) == handCount * provinceVal)){
                printf("FAIL - Test player %d with %d province cards in hand.\n", p, handCount);
                printf("Score = %d, expected = %d\n", scoreFor(p,&gS), handCount * provinceVal);
            }         

            memset(&gS, 23, sizeof(struct gameState));   
            initializeGame(2, k, seed, &gS); 
            gS.handCount[p] = handCount;                 
            memcpy(gS.hand[p], great_hallA, sizeof(int) * handCount); 
            if(!(scoreFor(p,&gS) == handCount * great_hallVal)){
                printf("FAIL - Test player %d with %d great hall cards in hand.\n", p, handCount);
                printf("Score = %d, expected = %d\n", scoreFor(p,&gS), handCount * great_hallVal);
            }

            memset(&gS, 23, sizeof(struct gameState));   
            initializeGame(2, k, seed, &gS); 
            gS.handCount[p] = handCount;                 
            memcpy(gS.hand[p], gardensA, sizeof(int) * handCount); 
			//assert fails after 10
        	if(!(scoreFor(p,&gS) == (handCount / 10))){                                     //assert gardens correct
                printf("FAIL - Test player %d with %d garden cards in hand.\n", p, handCount);
                printf("Score = %d, expected = %d\n", scoreFor(p,&gS), (handCount / 10));   //1 point for every 10 cards
            }									      
        }





        //bug here, score doesn't correctly account for discard points
        //assertions will all fail
        //score is always 1 or more higher than should be
        for(discardCount = 0; discardCount <= TEST_SIZE; discardCount++){
            memset(&gS, 23, sizeof(struct gameState));   
            initializeGame(2, k, seed, &gS); 
            gS.discardCount[p] = discardCount;               
            memcpy(gS.discard[p], curseA, sizeof(int) * discardCount);
        	if(!(scoreFor(p,&gS) == discardCount * curseVal)){
                printf("FAIL - Test player %d with %d curse cards in discard.\n", p, discardCount);
                printf("Score = %d, expected = %d\n", scoreFor(p,&gS), discardCount * curseVal);
            }
            
            memset(&gS, 23, sizeof(struct gameState));
            initializeGame(2, k, seed, &gS);
            gS.discardCount[p] = discardCount;  
            memcpy(gS.discard[p], estateA, sizeof(int) * discardCount);
            if(!(scoreFor(p,&gS) == discardCount * estateVal)){
                printf("FAIL - Test player %d with %d estate cards in discard.\n", p, discardCount);
                printf("Score = %d, expected = %d\n", scoreFor(p,&gS), discardCount * estateVal);
            }       
          
            memset(&gS, 23, sizeof(struct gameState));
            initializeGame(2, k, seed, &gS);
            gS.discardCount[p] = discardCount;
            memcpy(gS.discard[p], duchyA, sizeof(int) * discardCount);
            if(!(scoreFor(p,&gS) == discardCount * duchyVal)){
                printf("FAIL - Test player %d with %d duchy cards in discard.\n", p, discardCount);
                printf("Score = %d, expected = %d\n", scoreFor(p,&gS), discardCount * duchyVal);
            }    

            memset(&gS, 23, sizeof(struct gameState));
            initializeGame(2, k, seed, &gS);
            gS.discardCount[p] = discardCount;
            memcpy(gS.discard[p], provinceA, sizeof(int) * discardCount);
            if(!(scoreFor(p,&gS) == discardCount * provinceVal)){
                printf("FAIL - Test player %d with %d province cards in discard.\n", p, discardCount);
                printf("Score = %d, expected = %d\n", scoreFor(p,&gS), discardCount * provinceVal);
            }        
           
            memset(&gS, 23, sizeof(struct gameState));
            initializeGame(2, k, seed, &gS);
            gS.discardCount[p] = discardCount;
            memcpy(gS.discard[p], great_hallA, sizeof(int) * discardCount);
            if(!(scoreFor(p,&gS) == discardCount * great_hallVal)){
                printf("FAIL - Test player %d with %d great hall cards in discard.\n", p, discardCount);
                printf("Score = %d, expected = %d\n", scoreFor(p,&gS), discardCount * great_hallVal);
            }    

            memset(&gS, 23, sizeof(struct gameState));
            initializeGame(2, k, seed, &gS);
            gS.discardCount[p] = discardCount;
            memcpy(gS.discard[p], gardensA, sizeof(int) * discardCount);
            if(!(scoreFor(p,&gS) == (discardCount / 10))){
                printf("FAIL - Test player %d with %d garden cards in discard.\n", p, discardCount);
                printf("Score = %d, expected = %d\n", scoreFor(p,&gS), (discardCount / 10));
            }         
        }




        //bug here
        //assertions will all fail
        //score is always one or zero
        for(deckCount = 0; deckCount <= TEST_SIZE; deckCount++){
            memset(&gS, 23, sizeof(struct gameState));
            initializeGame(2, k, seed, &gS);
            gS.deckCount[p] = deckCount;
            memcpy(gS.deck[p], curseA, sizeof(int) * deckCount);
        	if(!(scoreFor(p,&gS) == deckCount * curseVal)){
                printf("FAIL - Test player %d with %d curse cards in deck.\n", p, deckCount);
                printf("Score = %d, expected = %d\n", scoreFor(p,&gS), deckCount * curseVal);
            }
           
            memset(&gS, 23, sizeof(struct gameState));
            initializeGame(2, k, seed, &gS);
            gS.deckCount[p] = deckCount;
            memcpy(gS.deck[p], estateA, sizeof(int) * deckCount);
            if(!(scoreFor(p,&gS) == deckCount * estateVal)){
                printf("FAIL - Test player %d with %d estate cards in deck.\n", p, deckCount);
                printf("Score = %d, expected = %d\n", scoreFor(p,&gS), deckCount * estateVal);
            }

            memset(&gS, 23, sizeof(struct gameState));
            initializeGame(2, k, seed, &gS);
            gS.deckCount[p] = deckCount;
            memcpy(gS.deck[p], duchyA, sizeof(int) * deckCount);
            if(!(scoreFor(p,&gS) == deckCount * duchyVal)){
                printf("FAIL - Test player %d with %d duchy cards in deck.\n", p, deckCount);
                printf("Score = %d, expected = %d\n", scoreFor(p,&gS), deckCount * duchyVal);
            }     

            memset(&gS, 23, sizeof(struct gameState));
            initializeGame(2, k, seed, &gS);
            gS.deckCount[p] = deckCount;
            memcpy(gS.deck[p], provinceA, sizeof(int) * deckCount);
            if(!(scoreFor(p,&gS) == deckCount * provinceVal)){
                printf("FAIL - Test player %d with %d province cards in deck.\n", p, deckCount);
                printf("Score = %d, expected = %d\n", scoreFor(p,&gS), deckCount * provinceVal);
            }        

            memset(&gS, 23, sizeof(struct gameState));
            initializeGame(2, k, seed, &gS);
            gS.deckCount[p] = deckCount;
            memcpy(gS.deck[p], great_hallA, sizeof(int) * deckCount);
            if(!(scoreFor(p,&gS) == deckCount * great_hallVal)){
                printf("FAIL - Test player %d with %d great hall cards in deck.\n", p, deckCount);
                printf("Score = %d, expected = %d\n", scoreFor(p,&gS), deckCount * great_hallVal);
            }     

            memset(&gS, 23, sizeof(struct gameState));
            initializeGame(2, k, seed, &gS);
            gS.deckCount[p] = deckCount;
            memcpy(gS.deck[p], gardensA, sizeof(int) * deckCount);
            if(!(scoreFor(p,&gS) == (discardCount / 10))){
                printf("FAIL - Test player %d with %d garden cards in deck.\n", p, deckCount);
                printf("Score = %d, expected = %d\n", scoreFor(p,&gS), (discardCount / 10));
            }         
        }
    }

	printf("All tests complete.\n");
    printf("Tests that failed printed information.\n");
            
	return 0;
}